<?php
/**
 * Created by PhpStorm.
 * User: xsp
 * Date: 2018/4/16
 * Time: 19:51
 */

namespace backend\controllers;


use backend\models\Admin;
use http\Url;
use yii\base\Model;
use yii\web\Controller;
use Yii;

class PublicController extends CommonController
{
    public $verbs = ['login'=>['POST','GET']];
    public $mustLogin = ['logout','seekpass'];
    public $except = ['login'];
    public $layout = false;
    public function actionLogin()
    {
        print_r($_SESSION);
//        print_r($this->behaviors());die;

        $this->layout = 'login';
        $model = new Admin();
        if(Yii::$app->request->isPost){
           if($model->login(Yii::$app->request->post()))
           {
               return $this->redirect(['index/index']);
           }
        }

        return $this->render('login',['model'=>$model]);
    }

    public function actionLogout()
    {
        var_dump($_SESSION);
        Yii::$app->admin->logout();
        return   $this->redirect(['public/login']);
    }

    public function actionSeekpass()
    {
        $this->layout = 'login';
        $model = new Admin();
        if(Yii::$app->request->isPost)
        {
            if($model->seekPass(Yii::$app->request->post()))
            {
                $this->redirect(['login']);
            }
        }
        return $this->render('seekpass',['model'=>$model]);
    }
}